import Vue from 'vue'
import Vuex from 'vuex'
import Home from '../views/home/module'
import ArticleList from '../views/articleList/module'
import ArticleContent from '../views/articleContent/module'
import { ArticleService } from '../services'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    searchMomentList: [],
    isLogin: false,
    recommendArticleList: []
  },
  mutations: {
    setSearchMomentList(state, payload) {
      state.searchMomentList = payload
    },
    isLogin(state) {
      state.isLogin = true
    },
    noLogin(state) {
      state.isLogin = false
    },
    setRecommendArticleList(state, payload) {
      state.recommendArticleList = payload
    }
  },
  actions: {
    async getSearchMomentList({ commit }, payload) {
      const res = await ArticleService.getSearchMomentList(payload)
      commit('setSearchMomentList', res.data.result)
    },
    async getRecommendArticleList({ commit }, payload) {
      const res = await ArticleService.getRecommendArticleList(payload)
      commit('setRecommendArticleList', res.data.result)
    }
  },
  modules: {
    Home,
    ArticleList,
    ArticleContent
  }
})
